package XueShengLian;
/**
 * DVDUI
 */
import java.text.ParseException;
import java.util.Scanner;
public class DvdUI {
	private static DvdShop  shop =null;
	 static Scanner  input =new Scanner(System.in);
	 
	 
	 public DvdUI(String name){
	  shop = new DvdShop(name);
	 }
	 
	 public void init(){
	  shop.add("罗马假日");
	  shop.add("风声鹤唳");
	  shop.add("浪漫满屋"); 
	 }
	 public void mainMenu() throws ParseException{
	  System.out.println("欢迎使用迷你DVD管理器");
	  System.out.println("---------------------");
	  System.out.println("1.新增DVD");
	  System.out.println("2.查看DVD");
	  System.out.println("3.删除DVD");
	  System.out.println("4.借出DVD");
	  System.out.println("5.归还DVD");
	  System.out.println("6.退        出");
	  System.out.println("---------------------");
	  System.out.print("请选择 ：");
	  int choice = input.nextInt();
	  switch(choice) {
	  case 1:
	   add();
	   break;
	  case 2:
	   show();
	   break;
	  case 3:
	   delete();
	   break;
	  case 4:
	   loan();
	   break;
	  case 5:
	   back();
	   break;
	  case 6:
	   System.out.println("感谢您的使用，程序将在3秒后退出.....");
	   try {
	    Thread.sleep(3000);
	   } catch (InterruptedException e) {
	    e.printStackTrace();
	   }
	   System.exit(0);
	   break;
	  }
	  System.out.print("输入0返回:");
	  input.next();
	  mainMenu();
	  
	 }
	 /**
	  * 添加dvd
	  */
	 public  void add(){
	  System.out.println("---->添加DVD");
	  //1.提示用户输入dvd的名字
	  System.out.print("请输入需要入库的DVD名称:");
	  String name = input.next();
	  
	  //3.将dvd的名字放进去
	  try{
	  shop.add(name);
	  //4.提示成功
	  System.out.println("添加<<"+name+">>成功");
	  }catch (RuntimeException e) {
	   System.out.println(e);
	  }
	  System.out.println("***************************");
	 }
	 /**
	  * 查询dvd 
	  */
	 public  void show(){
	  System.out.println("--->查看DVD");
	  if(shop.isEmpty()){
	   System.out.println("没有任何DVD信息");
	   return;
	  }
	  System.out.println("序号\t状态\t\t名称\t\t\t借出日期\t\t\t借出次数");
	  //循环输出信息
	  for(int i=0;i<shop.size();i++){
	      System.out.println((i+1)+"\t"+shop.get(i));
	  }
	  System.out.println("***************************");
	 }
	 /*
	  * 删除DVD delete
	  */
	 public static void delete() {
	  System.out.println("------>删除DVD");
	  System.out.println();
	  System.out.print("请输入DVD名称：");
	  String name = input.next();
	  //3.将dvd的名字放进去
	  try{
	  shop.delete(name);
	  //4.提示成功
	  System.out.println("删除《"+name+"》成功!");
	  }catch (RuntimeException e) {
	   System.out.println(e);
	  }
	  System.out.println("***************************");
	 }
	 /*
	  * 借出DVD  loan
	  */
	 public static void loan() {
	  System.out.println("------>借出DVD");
	  System.out.println();
	  System.out.print("请输入DVD名称：");
	  String name = input.next();
	  try{
	   shop.loan(name);
	   //4.提示成功
	   System.out.println("借出《"+name+"》成功!");
	   }catch (RuntimeException e) {
	    System.out.println(e);
	   }
	  System.out.println("***************************");
	 }
	 /*
	  * 归还DVD  back
	  */
	 public static void back() throws ParseException {
	  System.out.println("------>归还DVD");
	  System.out.println();
	  System.out.print("请输入DVD名称：");
	  String name = input.next();
	  try{
	   int rent = shop.back(name);
	   System.out.println("租金为："+rent);
	   //4.提示成功
	   System.out.println("归还《"+name+"》成功!");
	   }catch (RuntimeException e) {
	    System.out.println(e);
	   }
	  System.out.println("***************************");
	 }
}
